<template>
<div id="app">
  <el-card style="width: 80%;margin: auto">
    <div style="padding: 10px 0">
      <el-input style="width: 80%" size="medium" placeholder="请输入问题关键字" suffix-icon="el-icon-search" v-model="problem"></el-input>
      <el-button class="ml-5" size="medium" type="primary" @click="load" plain>搜索</el-button>
      <el-button class="ml-5" size="medium" type="warning" @click="reset" plain>重置</el-button>
    </div>
    <div :title="item.problem" v-for="item in questions" :key="item.id" class="d2">
      <el-link style="margin-bottom: 10px; margin-top: 10px" @click="$router.push({path: '/doctor/question',query:{question: item}})">{{item.problem}}</el-link>
      <span v-if="isReply(item.replyList)" style="color: orange;">(已回复)</span><br/>
      <br/>
      <span style="font-size: 10px; color: darkgray">回复数：{{ item.replyList.length }}</span>
      <div style="float: right">
        <span style="font-size: 10px; color: darkgray;" v-if="item.replyList.length >= 1">{{ item.replyList[0].createtime }}</span>
      </div>
      <br/>
      <hr/>
    </div>
  </el-card>
</div>
</template>

<script>
export default {
  name: "Reply",
  data() {
    return {
      questions: {},
      replies: {},
      dateTime: "",
      problem: "",
      phy: localStorage.getItem("phy") ? JSON.parse(localStorage.getItem("phy")) : {},
      flag: false,
      replyList: {}
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      console.log("问题" + this.problem)
      this.request.post("/question/list?problem=" + this.problem).then(res => {
        console.log(res)
        this.questions = res
      })
    },
    isReply(res){
      for(let i=0;i<res.length;i++){
        if(res[i].phyId === this.phy.id){
          return true
        }
      }
      return false
    },
    reset(){
      this.problem = ""
      this.load()
    },
  }
}
</script>

<style scoped>
#app{
  padding-top: 20px;
  display:flex;
  flex-direction: column;  /* 按照列column(垂直方向)排列*/
  justify-content: center;
  align-items: center;
}
</style>
